/**
 * Created by Administrator on 2016/5/8.
 */
$(document).ready(function(){
    $("#password").blur(function(){
        //noinspection JSJQueryEfficiency
        if ("" == $("#password").val() || $("#password").val() == undefined) {
            alert('请输入原密码！');
            $("#password").focus();
        }else{
            $.ajax({
                url: "/admin/confirmPwd",
                type:'post',
                data:$('#modifyPwdForm').serialize(),
                success:function(data){
                    if("0" == data){
                        alert('输入密码不正确');
                        $("#password").focus();
                    }
                }
            });
        }
    });
    $("#newPassword").blur(function(){
        //noinspection JSJQueryEfficiency
        if("" == $("#newPassword").val() || $("#newPassword").val() == undefined){
            alert('请输入新密码');
            $("#newPassword").focus();
        }else{
            if($("#password").val() == $("#newPassword").val()){
                alert('新密码与原密码相同！');
            }
        }
    });
    $("#reNewPassword").blur(function(){
        //noinspection JSJQueryEfficiency
        if("" == $("#reNewPassword").val() || $("#reNewPassword").val() == undefined){
            alert('请确认密码');
            $("#newPassword").focus();
        }else{
            if($("#reNewPassword").val() != $("#newPassword").val()){
                alert('确认密码与新密码不一致！');
            }
        }
    });

    $("#confirmBtn").click(function(){
        //noinspection JSJQueryEfficiency
        if ("" == $("#password").val() || $("#password").val() == undefined) {
            alert('请输入原密码！');
            return false;
        }
        //noinspection JSJQueryEfficiency
        if("" == $("#newPassword").val() || $("#newPassword").val() == undefined){
            alert('请输入新密码');
            $("#newPassword").focus();
            return false;
        }else{
            //noinspection JSJQueryEfficiency
            if($("#password").val() == $("#newPassword").val()){
                alert('新密码与原密码相同！');
                $("#newPassword").focus();
                return false;
            }
        }
        //noinspection JSJQueryEfficiency
        if("" == $("#reNewPassword").val() || $("#reNewPassword").val() == undefined){
            alert('请确认密码');
            $("#newPassword").focus();
            return false;
        }else{
            //noinspection JSJQueryEfficiency
            if($("#reNewPassword").val() != $("#newPassword").val()){
                alert('确认密码与新密码不一致！');
                $("#reNewPassword").focus();
                return false;
            }
        }
        $.ajax({
            url: "/admin/changePwd",
            type:'post',
            data:$('#modifyPwdForm').serialize(),
            success:function(data){
                if("1" == data){
                    alert('修改密码成功！');
                    $('#confirmBtn').attr({"data-dismiss": "modal", "aria-hidden" : "true"});
                }else{
                    alert('修改密码失败！');
                }
            }
        });
    });
});
